/* 
 * Copyright 2019 Patrik Karlström.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package se.trixon.almond.nbp.dialogs;

import org.openide.DialogDescriptor;
import org.openide.util.NbBundle;
import se.trixon.almond.nbp.AlmondOptions;

/**
 *
 * @author Patrik Karlström
 */
@NbBundle.Messages({
    "CTL_ConfirmExitTitle=Confirm Exit"})
public class ConfirmExitDialog extends javax.swing.JPanel {

    public static DialogDescriptor getDescriptor() {
        return new DialogDescriptor(new ConfirmExitDialog(), Bundle.CTL_ConfirmExitTitle());
    }

    /**
     * Creates new form ConfirmExitPanel
     */
    public ConfirmExitDialog() {
        initComponents();
        askCheckBox.setSelected(!AlmondOptions.INSTANCE.getConfirmExit());
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        iconLabel = new javax.swing.JLabel();
        messageLabel = new javax.swing.JLabel();
        askCheckBox = new javax.swing.JCheckBox();

        setBorder(javax.swing.BorderFactory.createEmptyBorder(16, 16, 1, 16));

        iconLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/se/trixon/almond/dialogs/system-help.png"))); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(messageLabel, org.openide.util.NbBundle.getMessage(ConfirmExitDialog.class, "ConfirmExitDialog.messageLabel.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(askCheckBox, org.openide.util.NbBundle.getMessage(ConfirmExitDialog.class, "ConfirmExitDialog.askCheckBox.text")); // NOI18N
        askCheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                askCheckBoxActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(iconLabel)
                        .addGap(18, 18, 18)
                        .addComponent(messageLabel))
                    .addComponent(askCheckBox))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(iconLabel)
                    .addComponent(messageLabel))
                .addGap(12, 12, 12)
                .addComponent(askCheckBox)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void askCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_askCheckBoxActionPerformed
        AlmondOptions.INSTANCE.setConfirmExit(!askCheckBox.isSelected());
    }//GEN-LAST:event_askCheckBoxActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox askCheckBox;
    private javax.swing.JLabel iconLabel;
    private javax.swing.JLabel messageLabel;
    // End of variables declaration//GEN-END:variables
}
